<?php
class Login_Model_Registred {
	
	private $validation;
	private $secure;
	private $addValues;
	private $session;
	
	public function __construct(){
		$this->validation = new Core_Model_Validation();
		$this->secure = new Core_Data_Secure();
		$this->addValues = new Login_Data_AddUser;
	}
	
	public function addRegistredValues(array $postVars){
		try {
			if($this->validation->validation($postVars)){
				return $this->addAllValues($postVars);
			}
			else {
				echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?login&page=login">';
			}
		}
		catch(Exception $e){
			echo $e->getMessage();
		}
	}
	
	
	public function addAllValues(array $postVars){
		$postVars = $this->secure->parseData($postVars);
		try {
			if($postVars['password'] == $postVars['password_two']){
				$this->addValues->add($postVars);
				echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?login&page=login">';
			}
			else {
				echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?login&page=login">';
			}
		}
		catch(Exception $e){
			echo $e->getMessage();
		}
	}
}